package cmgine.com.testqq.start;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.PagerTitleStrip;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;

import java.util.ArrayList;

import cmgine.com.testqq.R;

/**
 * Created by apple on 12/23/15.
 */
public class PageActivity extends Activity {
    private ViewPager mViewPager;
    private PagerTitleStrip mPagerTitleStrip;
    private static final String ACTIVITY_TAG="LogDemo";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.viewpager_activity);

        mViewPager = (ViewPager)findViewById(R.id.viewpager);
        mPagerTitleStrip = (PagerTitleStrip)findViewById(R.id.pagertitle);
        LayoutInflater mLi = LayoutInflater.from(this);

        View view1 = mLi.inflate(R.layout.viewpager_activity_item1, null);
        View view2 = mLi.inflate(R.layout.viewpager_activity_item2, null);
        View view3 = mLi.inflate(R.layout.viewpager_activity_item3, null);

        final ArrayList<View> views = new ArrayList<>();
        views.add(view1);
        views.add(view2);
        views.add(view3);

        PagerAdapter pagerAdapter = new PagerAdapter() {
            @Override
            public int getCount() {
                return views.size();
            }

            @Override
            public boolean isViewFromObject(View view, Object object) {
                return view == object;
            }

            @Override
            public void destroyItem(View container, int position, Object object) {
                ((ViewPager) container).removeView(views.get(position));
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return null;
            }

            @Override
            public Object instantiateItem(View container, int position) {
                ((ViewPager) container).addView(views.get(position));
                return views.get(position);
            }
        };
        mViewPager.setAdapter(pagerAdapter);
    }

    public void startAction(View v) {
        Log.d(ACTIVITY_TAG, "点击button");
        Intent intent = new Intent();
        intent.setClass(PageActivity.this, WhatNewDoorActivity.class);
        startActivity(intent);
        PageActivity.this.finish();
    }
}

